package com.cleaningcloud.erp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.erp.domain.vo.ErpAccountsReceivableVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.erp.domain.ErpAccountsReceivable;
import com.cleaningcloud.erp.service.IErpAccountsReceivableService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.web.page.TableDataInfo;

/**
 * 应收账款Controller
 * 
 * @author cleaningcloud
 * @date 2024-10-02
 */
@RestController
@RequestMapping("/ErpAccountsReceivable")
public class ErpAccountsReceivableController extends BaseController
{
    @Autowired
    private IErpAccountsReceivableService erpAccountsReceivableService;

    /**
     * 查询应收账款列表
     */
    @RequiresPermissions("erp:ErpAccountsReceivable:list")
    @GetMapping("/list")
    public TableDataInfo list(ErpAccountsReceivable erpAccountsReceivable)
    {
        startPage();
        List<ErpAccountsReceivableVo> list = erpAccountsReceivableService.selectErpAccountsReceivableList(erpAccountsReceivable);
        return getDataTable(list);
    }

    /**
     * 导出应收账款列表
     */
    @RequiresPermissions("erp:ErpAccountsReceivable:export")
    @Log(title = "应收账款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpAccountsReceivable erpAccountsReceivable)
    {
        List<ErpAccountsReceivableVo> list = erpAccountsReceivableService.selectErpAccountsReceivableList(erpAccountsReceivable);
        ExcelUtil<ErpAccountsReceivableVo> util = new ExcelUtil<ErpAccountsReceivableVo>(ErpAccountsReceivableVo.class);
        util.exportExcel(response, list, "应收账款数据");
    }

    /**
     * 获取应收账款详细信息
     */
    @RequiresPermissions("erp:ErpAccountsReceivable:query")
    @GetMapping(value = "/{receivableId}")
    public AjaxResult getInfo(@PathVariable("receivableId") Long receivableId)
    {
        return success(erpAccountsReceivableService.selectErpAccountsReceivableByReceivableId(receivableId));
    }

    /**
     * 新增应收账款
     */
    @RequiresPermissions("erp:ErpAccountsReceivable:add")
    @Log(title = "应收账款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpAccountsReceivable erpAccountsReceivable)
    {
        return toAjax(erpAccountsReceivableService.insertErpAccountsReceivable(erpAccountsReceivable));
    }

    /**
     * 修改应收账款
     */
    @RequiresPermissions("erp:ErpAccountsReceivable:edit")
    @Log(title = "应收账款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpAccountsReceivable erpAccountsReceivable)
    {
        return toAjax(erpAccountsReceivableService.updateErpAccountsReceivable(erpAccountsReceivable));
    }

    /**
     * 删除应收账款
     */
    @RequiresPermissions("erp:ErpAccountsReceivable:remove")
    @Log(title = "应收账款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{receivableIds}")
    public AjaxResult remove(@PathVariable Long[] receivableIds)
    {
        return toAjax(erpAccountsReceivableService.deleteErpAccountsReceivableByReceivableIds(receivableIds));
    }


    /**
     * 应付账款收款
     */
    @RequiresPermissions("erp:ErpAccountsReceivable:receivingPayments")
    @Log(title = "应付账款收款", businessType = BusinessType.UPDATE)
    @PutMapping("/receivingPayments")
    public AjaxResult receivingPayments(@RequestBody ErpAccountsReceivable erpAccountsReceivable)
    {
        return toAjax(erpAccountsReceivableService.receivingPaymentsErpAccountsPayable(erpAccountsReceivable));
    }

    /**
     * 应付账款开票
     */
    @RequiresPermissions("erp:ErpAccountsPayable:invoicing")
    @Log(title = "应付账款开票", businessType = BusinessType.UPDATE)
    @PutMapping("/invoicing")
    public AjaxResult invoicing(@RequestBody ErpAccountsReceivable erpAccountsReceivable)
    {
        return toAjax(erpAccountsReceivableService.invoicingErpAccountsPayable(erpAccountsReceivable));
    }

    /**
     * 获取应收账款顶部统计
     */
    @GetMapping(value = "/statistics")
    public AjaxResult statistics()
    {
        return success(erpAccountsReceivableService.statistics());
    }
}
